package com.lvhx.springboot.filter;

import com.alibaba.fastjson.JSON;
import com.alipay.sofa.rpc.core.exception.SofaRpcException;
import com.alipay.sofa.rpc.core.request.SofaRequest;
import com.alipay.sofa.rpc.core.response.SofaResponse;
import com.alipay.sofa.rpc.filter.Filter;
import com.alipay.sofa.rpc.filter.FilterInvoker;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class MyFilter extends Filter {
    public MyFilter() {
    }

    @Override
    public boolean needToLoad(FilterInvoker invoker) {
        return true;
    }

    @Override
    public SofaResponse invoke(FilterInvoker invoker, SofaRequest request) throws SofaRpcException {
        log.info("=====进入自定义过滤器=====");
        log.info("=====请求参数：{}", JSON.toJSONString(request));
        SofaResponse response = invoker.invoke(request);
        log.info("=====返回参数：{}", JSON.toJSONString(response));
        return response;
    }
}
